import store from "@/redux/index";

/**
 * 按钮权限
 * @param {String} params 传入的按钮权限码
 * @returns {Boolean}
 */

export const hasPermi = (params) => {
  const roleType = ["admin", "superAdmin"];
  // 登录的角色账号
  const userInfo = store.getState().useUserStore.userInfo;
  // 获取redux中的按钮权限码
  let permissionDatas = store.getState().useUserStore.permissionBtns;
  let hasPermission;
  // 判断是超管和管理员账号不设置按钮权限
  if (roleType.includes(userInfo.username)) {
    hasPermission = true;
  } else {
    hasPermission = permissionDatas.includes(params);
  }

  return hasPermission;
};
